#!/usr/bin/env node

const http = require('https'),
      log = console.log,
      url = require('url'),
      city = process.argv[2] || '石家庄',
      //addr = 'https://api.66mz8.com/api/weather.php?location=%e7%9f%b3%e5%ae%b6%e5%ba%84';
      addr = 'https://api.66mz8.com/api/weather.php?location=' + city;

log(addr);
log(global.encodeURI(addr));//将汉字转成ASCII码
process.exit();

let opt = url.parse(addr);//将addr解析，放入opt中
opt.header = {
  'user-agent':'curl/7.2.0'
};
http.get(opt, (res)=>{//addr:请求的url地址,res流：响应体数据
  log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);

  log(res.headers);

  res.pipe(process.stdout);

});

